<template>
  <div class="app-container">
    <!--公司联系人-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <label class="el-form-item-label">客户编号</label>
        {{ lianxirenval }}
        <label class="el-form-item-label">客户名称</label>
        {{ lkmCustName }}
        <!-- <rrOperation :crud="crud" /> -->
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="客户编号" prop="lkmCustNo">
            <!-- <el-input v-model="form.lkmCustNo" style="width: 370px;" /> -->
            {{ form.lkmCustNo=lianxirenval }}
          </el-form-item>
          <el-form-item label="客户名称" prop="lkmCustName">
            {{ form.lkmCustName=lkmCustName }}
            <!-- <el-input v-model="form.lkmCustName" style="width: 370px;" /> -->
          </el-form-item>
          <el-form-item label="姓名" prop="lkmName">
            <el-input v-model="form.lkmName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="性别 ">
            <el-radio v-for="item in dict.lkm_sex" :key="item.id" v-model="form.lkmSex" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="职位">
            <el-input v-model="form.lkmPostion" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="办公电话 " prop="lkmTel">
            <el-input v-model="form.lkmTel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="手机">
            <el-input v-model="form.lkmMobile" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.lkmMemo" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="lkmId" label="编号" />
        <el-table-column prop="lkmCustNo" label="客户编号" >
          <template slot-scope="scope">
              {{ scope.row.lkmCustNo = lianxirenval }}
          </template>
        </el-table-column>
        <el-table-column prop="lkmCustName" label="客户名称" />
        <el-table-column prop="lkmName" label="姓名" />
        <el-table-column prop="lkmSex" label="性别 ">
          <template slot-scope="scope">
            {{ dict.label.lkm_sex[scope.row.lkmSex] }}
          </template>
        </el-table-column>
        <el-table-column prop="lkmPostion" label="职位" />
        <el-table-column prop="lkmTel" label="办公电话 " />
        <el-table-column prop="lkmMobile" label="手机" />
        <el-table-column prop="lkmMemo" label="备注" />
        <el-table-column v-if="checkPer(['admin','cstLinkman:edit','cstLinkman:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudCstLinkman from '@/api/cstLinkman'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { lkmId: null, lkmCustNo: null, lkmCustName: null, lkmName: null, lkmSex: null, lkmPostion: null, lkmTel: null, lkmMobile: null, lkmMemo: null }
export default {
  name: 'CstLinkman',
  components: { pagination, crudOperation, udOperation },

  mixins: [presenter(), header(), form(defaultForm), crud()],
  props: {
    lianxirenval: {
      type: String,
      default: ''
    },
    lkmCustName: {
      type: String,
      default: ''
    }
  },
  dicts: ['lkm_sex'],
  cruds() {
    return CRUD({ queryOnPresenterCreated: false, title: '客户联系人', url: 'api/cstLinkman', idField: 'lkmId', sort: 'lkmId,desc', crudMethod: { ...crudCstLinkman }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'cstLinkman:add'],
        edit: ['admin', 'cstLinkman:edit'],
        del: ['admin', 'cstLinkman:del']
      },
      rules: {
        lkmCustNo: [
          { required: true, message: '客户编号不能为空', trigger: 'blur' }
        ],
        lkmCustName: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        lkmName: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        lkmTel: [
          { required: true, message: '办公电话 不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'lkmCustNo', display_name: '客户编号' },
        { key: 'lkmCustName', display_name: '客户名称' }
      ]
    }
  },
  watch: {
    'lianxirenval'() {
      this.crud.params = { lkmCustNo: this.lianxirenval }
      this.crud.toQuery()
    }
  },
  created() {
    this.crud.params = { lkmCustNo: this.lianxirenval }
    this.crud.toQuery()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
